class Solution:
    def isPalindrome(self, x: int) -> bool:
        # 如果是0,一定是回文数
        if x == 0:
            return True
        # 如果是负数,一定不是回文数
        if x < 0:
            return False
        # 如果是0结束,一定不是回文数
        str_x = str(x)
        if str_x.endswith('0'):
            return False
        # 解题方法2: 翻转一半的数字
        mid = len(str_x) // 2
        # 前半段
        str_before = str_x[:mid]
        # 后半段
        str_next = str_x[mid:]
        str_next = str_next[::-1]
        # 比较
        for i in range(mid):
            if str_before[i] != str_next[i]:
                return False
        else:
            return True


num1 = 121
num2 = -121
num3 = 10

solution = Solution()
print(solution.isPalindrome(num1))
print(solution.isPalindrome(num2))
print(solution.isPalindrome(num3))
